﻿using System;
using System.Collections.Generic;
using System.Linq;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.BarterSystem.Barterables;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Election
{
	// Token: 0x02000273 RID: 627
	public class DeclareWarDecision : KingdomDecision
	{
		// Token: 0x0600212D RID: 8493 RVA: 0x0008D393 File Offset: 0x0008B593
		internal static void AutoGeneratedStaticCollectObjectsDeclareWarDecision(object o, List<object> collectedObjects)
		{
			((DeclareWarDecision)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x0600212E RID: 8494 RVA: 0x0008D3A1 File Offset: 0x0008B5A1
		protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
			base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			collectedObjects.Add(this.FactionToDeclareWarOn);
		}

		// Token: 0x0600212F RID: 8495 RVA: 0x0008D3B6 File Offset: 0x0008B5B6
		internal static object AutoGeneratedGetMemberValueFactionToDeclareWarOn(object o)
		{
			return ((DeclareWarDecision)o).FactionToDeclareWarOn;
		}

		// Token: 0x06002130 RID: 8496 RVA: 0x0008D3C3 File Offset: 0x0008B5C3
		public DeclareWarDecision(Clan proposerClan, IFaction factionToDeclareWarOn) : base(proposerClan)
		{
			this.FactionToDeclareWarOn = factionToDeclareWarOn;
		}

		// Token: 0x06002131 RID: 8497 RVA: 0x0008D3D4 File Offset: 0x0008B5D4
		public override bool IsAllowed()
		{
			TextObject textObject;
			return !this.FactionToDeclareWarOn.IsKingdomFaction || Campaign.Current.Models.KingdomDecisionPermissionModel.IsWarDecisionAllowedBetweenKingdoms(base.Kingdom, this.FactionToDeclareWarOn as Kingdom, out textObject);
		}

		// Token: 0x06002132 RID: 8498 RVA: 0x0008D417 File Offset: 0x0008B617
		public override int GetProposalInfluenceCost()
		{
			return Campaign.Current.Models.DiplomacyModel.GetInfluenceCostOfProposingWar(base.ProposerClan);
		}

		// Token: 0x06002133 RID: 8499 RVA: 0x0008D433 File Offset: 0x0008B633
		public override TextObject GetGeneralTitle()
		{
			TextObject textObject = new TextObject("{=rtfoywJl}Declare war on the {KINGDOM_NAME}", null);
			textObject.SetTextVariable("KINGDOM_NAME", this.FactionToDeclareWarOn.InformalName);
			return textObject;
		}

		// Token: 0x06002134 RID: 8500 RVA: 0x0008D457 File Offset: 0x0008B657
		public override TextObject GetSupportTitle()
		{
			TextObject textObject = new TextObject("{=xM97H0oR}Vote for declaring war on the {KINGDOM_NAME}.", null);
			textObject.SetTextVariable("KINGDOM_NAME", this.FactionToDeclareWarOn.InformalName);
			return textObject;
		}

		// Token: 0x06002135 RID: 8501 RVA: 0x0008D47B File Offset: 0x0008B67B
		public override TextObject GetChooseTitle()
		{
			TextObject textObject = new TextObject("{=aQAI99d4}Declaring War on the {KINGDOM_NAME}", null);
			textObject.SetTextVariable("KINGDOM_NAME", this.FactionToDeclareWarOn.InformalName);
			return textObject;
		}

		// Token: 0x06002136 RID: 8502 RVA: 0x0008D49F File Offset: 0x0008B69F
		public override TextObject GetSupportDescription()
		{
			TextObject textObject = new TextObject("{=KSrNutEO}{FACTION_LEADER} will decide if war will be declared on the {KINGDOM_NAME}. You can pick your stance regarding this decision.", null);
			textObject.SetTextVariable("FACTION_LEADER", this.DetermineChooser().Leader.Name);
			textObject.SetTextVariable("KINGDOM_NAME", this.FactionToDeclareWarOn.InformalName);
			return textObject;
		}

		// Token: 0x06002137 RID: 8503 RVA: 0x0008D4E0 File Offset: 0x0008B6E0
		public override TextObject GetChooseDescription()
		{
			TextObject textObject = new TextObject("{=4JSzHkpt}As {?IS_FEMALE}queen{?}king{\\?}, you must decide if war will be declared on the {KINGDOM_NAME}", null);
			textObject.SetTextVariable("IS_FEMALE", this.DetermineChooser().Leader.IsFemale ? 1 : 0);
			textObject.SetTextVariable("KINGDOM_NAME", this.FactionToDeclareWarOn.InformalName);
			return textObject;
		}

		// Token: 0x06002138 RID: 8504 RVA: 0x0008D531 File Offset: 0x0008B731
		public override IEnumerable<DecisionOutcome> DetermineInitialCandidates()
		{
			yield return new DeclareWarDecision.DeclareWarDecisionOutcome(true, base.Kingdom, this.FactionToDeclareWarOn);
			yield return new DeclareWarDecision.DeclareWarDecisionOutcome(false, base.Kingdom, this.FactionToDeclareWarOn);
			yield break;
		}

		// Token: 0x06002139 RID: 8505 RVA: 0x0008D541 File Offset: 0x0008B741
		public override Clan DetermineChooser()
		{
			return base.Kingdom.RulingClan;
		}

		// Token: 0x0600213A RID: 8506 RVA: 0x0008D54E File Offset: 0x0008B74E
		protected override bool ShouldBeCancelledInternal()
		{
			return this.FactionToDeclareWarOn.IsEliminated || base.Kingdom.IsAtWarWith(this.FactionToDeclareWarOn);
		}

		// Token: 0x0600213B RID: 8507 RVA: 0x0008D570 File Offset: 0x0008B770
		public override void DetermineSponsors(MBReadOnlyList<DecisionOutcome> possibleOutcomes)
		{
			foreach (DecisionOutcome decisionOutcome in possibleOutcomes)
			{
				if (((DeclareWarDecision.DeclareWarDecisionOutcome)decisionOutcome).ShouldWarBeDeclared)
				{
					decisionOutcome.SetSponsor(base.ProposerClan);
				}
				else
				{
					base.AssignDefaultSponsor(decisionOutcome);
				}
			}
		}

		// Token: 0x0600213C RID: 8508 RVA: 0x0008D5DC File Offset: 0x0008B7DC
		public override void ApplyChosenOutcome(DecisionOutcome chosenOutcome)
		{
			if (((DeclareWarDecision.DeclareWarDecisionOutcome)chosenOutcome).ShouldWarBeDeclared)
			{
				DeclareWarAction.ApplyByKingdomDecision(base.Kingdom, this.FactionToDeclareWarOn);
			}
		}

		// Token: 0x0600213D RID: 8509 RVA: 0x0008D5FC File Offset: 0x0008B7FC
		public override TextObject GetSecondaryEffects()
		{
			return new TextObject("{=!}All supporters gains some relation with each other.", null);
		}

		// Token: 0x0600213E RID: 8510 RVA: 0x0008D609 File Offset: 0x0008B809
		public override void ApplySecondaryEffects(MBReadOnlyList<DecisionOutcome> possibleOutcomes, DecisionOutcome chosenOutcome)
		{
		}

		// Token: 0x0600213F RID: 8511 RVA: 0x0008D60C File Offset: 0x0008B80C
		public override TextObject GetChosenOutcomeText(DecisionOutcome chosenOutcome, KingdomDecision.SupportStatus supportStatus, bool isShortVersion = false)
		{
			TextObject textObject;
			if (((DeclareWarDecision.DeclareWarDecisionOutcome)chosenOutcome).ShouldWarBeDeclared)
			{
				if (base.IsSingleClanDecision())
				{
					textObject = new TextObject("{=Shk9QCDg}{AGGRESSOR_RULER.NAME} of the {AGGRESSOR_KINGDOM} has declared war on the {KINGDOM}.", null);
				}
				else if (supportStatus == KingdomDecision.SupportStatus.Majority)
				{
					textObject = new TextObject("{=cRpsjvOM}{AGGRESSOR_RULER.NAME} of the {AGGRESSOR_KINGDOM} has declared war on the {KINGDOM} with the support of {?AGGRESSOR_RULER.GENDER}her{?}his{\\?} council.", null);
				}
				else if (supportStatus == KingdomDecision.SupportStatus.Minority)
				{
					textObject = new TextObject("{=DphlPaF9}{AGGRESSOR_RULER.NAME} of the {AGGRESSOR_KINGDOM} has declared war on the {KINGDOM} despite opposition from {?AGGRESSOR_RULER.GENDER}her{?}his{\\?} council.", null);
				}
				else
				{
					textObject = new TextObject("{=RH8mgLEk}{AGGRESSOR_RULER.NAME} of the {AGGRESSOR_KINGDOM} has declared war on the {KINGDOM} with support from half of {?AGGRESSOR_RULER.GENDER}her{?}his{\\?} council.", null);
				}
			}
			else if (base.IsSingleClanDecision())
			{
				textObject = new TextObject("{=9WDK03GW}{AGGRESSOR_RULER.NAME} of the {AGGRESSOR_KINGDOM} chose not to go to war with the {KINGDOM}.", null);
			}
			else if (supportStatus == KingdomDecision.SupportStatus.Majority)
			{
				textObject = new TextObject("{=8RBZaQKk}{AGGRESSOR_RULER.NAME} of the {AGGRESSOR_KINGDOM} chose not to go to war with the {KINGDOM} with the support of {?AGGRESSOR_RULER.GENDER}her{?}his{\\?} council.", null);
			}
			else if (supportStatus == KingdomDecision.SupportStatus.Minority)
			{
				textObject = new TextObject("{=XaZyU3Cn}{AGGRESSOR_RULER.NAME} of the {AGGRESSOR_KINGDOM} chose not to go to war with the {KINGDOM} despite the wishes of {?AGGRESSOR_RULER.GENDER}her{?}his{\\?} council.", null);
			}
			else
			{
				textObject = new TextObject("{=5L0wDGhR}{AGGRESSOR_RULER.NAME} of the {AGGRESSOR_KINGDOM} chose not to go to war with the {KINGDOM}, with {?AGGRESSOR_RULER.GENDER}her{?}his{\\?} council evenly split.", null);
			}
			StringHelpers.SetCharacterProperties("AGGRESSOR_RULER", base.Kingdom.Leader.CharacterObject, textObject, false);
			textObject.SetTextVariable("AGGRESSOR_KINGDOM", base.Kingdom.EncyclopediaLinkWithName);
			textObject.SetTextVariable("KINGDOM", this.FactionToDeclareWarOn.InformalName);
			return textObject;
		}

		// Token: 0x06002140 RID: 8512 RVA: 0x0008D700 File Offset: 0x0008B900
		public override DecisionOutcome GetQueriedDecisionOutcome(MBReadOnlyList<DecisionOutcome> possibleOutcomes)
		{
			return possibleOutcomes.FirstOrDefault((DecisionOutcome t) => ((DeclareWarDecision.DeclareWarDecisionOutcome)t).ShouldWarBeDeclared);
		}

		// Token: 0x06002141 RID: 8513 RVA: 0x0008D727 File Offset: 0x0008B927
		public float CalculateSupport(Clan clan)
		{
			return this.DetermineSupport(clan, new DeclareWarDecision.DeclareWarDecisionOutcome(true, base.Kingdom, this.FactionToDeclareWarOn));
		}

		// Token: 0x06002142 RID: 8514 RVA: 0x0008D744 File Offset: 0x0008B944
		public override float DetermineSupport(Clan clan, DecisionOutcome possibleOutcome)
		{
			Hero leader = clan.Leader;
			DeclareWarDecision.DeclareWarDecisionOutcome declareWarDecisionOutcome = (DeclareWarDecision.DeclareWarDecisionOutcome)possibleOutcome;
			float num = (float)new DeclareWarBarterable(base.Kingdom, this.FactionToDeclareWarOn).GetValueForFaction(clan) * Campaign.Current.Models.DiplomacyModel.DenarsToInfluence();
			if (declareWarDecisionOutcome.ShouldWarBeDeclared)
			{
				float num2 = num;
				int num3 = clan.Leader.GetTraitLevel(DefaultTraits.Valor) * 20 - clan.Leader.GetTraitLevel(DefaultTraits.Mercy) * 10;
				return num2 + (float)num3;
			}
			float num4 = -num;
			int num5 = -clan.Leader.GetTraitLevel(DefaultTraits.Valor) * 20 + clan.Leader.GetTraitLevel(DefaultTraits.Mercy) * 10;
			return num4 + (float)num5;
		}

		// Token: 0x04000A56 RID: 2646
		[SaveableField(101)]
		public readonly IFaction FactionToDeclareWarOn;

		// Token: 0x02000586 RID: 1414
		public class DeclareWarDecisionOutcome : DecisionOutcome
		{
			// Token: 0x060045DA RID: 17882 RVA: 0x0014ACBC File Offset: 0x00148EBC
			internal static void AutoGeneratedStaticCollectObjectsDeclareWarDecisionOutcome(object o, List<object> collectedObjects)
			{
				((DeclareWarDecision.DeclareWarDecisionOutcome)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x060045DB RID: 17883 RVA: 0x0014ACCA File Offset: 0x00148ECA
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this.Kingdom);
				collectedObjects.Add(this.FactionToDeclareWarOn);
			}

			// Token: 0x060045DC RID: 17884 RVA: 0x0014ACEB File Offset: 0x00148EEB
			internal static object AutoGeneratedGetMemberValueShouldWarBeDeclared(object o)
			{
				return ((DeclareWarDecision.DeclareWarDecisionOutcome)o).ShouldWarBeDeclared;
			}

			// Token: 0x060045DD RID: 17885 RVA: 0x0014ACFD File Offset: 0x00148EFD
			internal static object AutoGeneratedGetMemberValueKingdom(object o)
			{
				return ((DeclareWarDecision.DeclareWarDecisionOutcome)o).Kingdom;
			}

			// Token: 0x060045DE RID: 17886 RVA: 0x0014AD0A File Offset: 0x00148F0A
			internal static object AutoGeneratedGetMemberValueFactionToDeclareWarOn(object o)
			{
				return ((DeclareWarDecision.DeclareWarDecisionOutcome)o).FactionToDeclareWarOn;
			}

			// Token: 0x060045DF RID: 17887 RVA: 0x0014AD17 File Offset: 0x00148F17
			public DeclareWarDecisionOutcome(bool shouldWarBeDeclared, Kingdom kingdom, IFaction factionToDeclareWarOn)
			{
				this.ShouldWarBeDeclared = shouldWarBeDeclared;
				this.Kingdom = kingdom;
				this.FactionToDeclareWarOn = factionToDeclareWarOn;
			}

			// Token: 0x060045E0 RID: 17888 RVA: 0x0014AD34 File Offset: 0x00148F34
			public override TextObject GetDecisionTitle()
			{
				TextObject textObject = new TextObject("{=kakxnaN5}{?SUPPORT}Yes{?}No{\\?}", null);
				textObject.SetTextVariable("SUPPORT", this.ShouldWarBeDeclared ? 1 : 0);
				return textObject;
			}

			// Token: 0x060045E1 RID: 17889 RVA: 0x0014AD5C File Offset: 0x00148F5C
			public override TextObject GetDecisionDescription()
			{
				if (base.SponsorClan != null && this.Kingdom != null && this.FactionToDeclareWarOn != null && base.SponsorClan != Clan.PlayerClan)
				{
					TextObject empty = TextObject.Empty;
					if (this.ShouldWarBeDeclared)
					{
						Campaign.Current.Models.DiplomacyModel.GetScoreOfDeclaringWar(this.Kingdom, this.FactionToDeclareWarOn, base.SponsorClan, out empty);
					}
					if (empty != TextObject.Empty)
					{
						return empty;
					}
				}
				if (this.ShouldWarBeDeclared)
				{
					return new TextObject("{=w9olmhv0}It is time to declare war", null);
				}
				return new TextObject("{=epnk9qIt}We oppose a declaration of war", null);
			}

			// Token: 0x060045E2 RID: 17890 RVA: 0x0014ADEE File Offset: 0x00148FEE
			public override string GetDecisionLink()
			{
				return null;
			}

			// Token: 0x060045E3 RID: 17891 RVA: 0x0014ADF1 File Offset: 0x00148FF1
			public override ImageIdentifier GetDecisionImageIdentifier()
			{
				return null;
			}

			// Token: 0x04001716 RID: 5910
			[SaveableField(100)]
			public readonly bool ShouldWarBeDeclared;

			// Token: 0x04001717 RID: 5911
			[SaveableField(110)]
			public readonly Kingdom Kingdom;

			// Token: 0x04001718 RID: 5912
			[SaveableField(120)]
			public readonly IFaction FactionToDeclareWarOn;
		}
	}
}
